package tt.love.hw.validator;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.validator.ValidatorResources;
import org.xml.sax.SAXException;

import tt.love.hw.common.ActionException;




public class AppValidatorListener implements ServletContextListener {

	public void contextDestroyed(ServletContextEvent arg0) {
		
	}

	public void contextInitialized(ServletContextEvent event) {
		
		InputStream in = null;
        ValidatorResources resources = null;
        try {
            in = event.getServletContext().getResourceAsStream("/WEB-INF/validator.xml");
            resources = new ValidatorResources(in);
        } catch (IOException e) {
			throw new ActionException(e);
		} catch (SAXException e) {
			throw new ActionException(e);
		} finally {
            if (in != null) {
                try {
					in.close();
				} catch (IOException e) {
				}
            }
        }
		
		event.getServletContext().setAttribute("ValidatorResources", resources);
		
	}

 
}
